// Nirma Studio, 2013
// OpenGl test MEBGE project
#include "inc.h"

int x = 0;
int y = 0;
bool down = false;

Marine    *m1   = new Marine(500,100);
Centipede *c1   = new Centipede(200,150);

void draw(void){
    glClear(GL_COLOR_BUFFER_BIT);
   
    nmCircle_grey(4, m1->cordX, m1->cordY);
    nmCircle_blue(8, c1->cordX, c1-> cordY);

  glutSwapBuffers();
}

void timer(int = 0){
  if(down){
    float d = sqrt(pow(m1->cordX - x, 2) + pow(m1->cordY - y, 2));
    if(m1->cordX < x)
        m1->cordX--;//m1->cordX += 5 * abs(x - m1->cordX) / d;
    else m1->cordX++;//m1->cordX -= 5 * abs(x - m1->cordX) / d;
    if(m1->cordY < y)
        m1->cordY--;       //m1->cordY += 5 * abs(y - m1->cordY) / d;
    else m1->cordY++;   //m1->cordY -= 5 * abs(x - m1->cordY) / d;
  }
  draw();
  glutTimerFunc(1, timer, 0);
}

void mouse(int botton, int state, int ax, int ay){
  down = state == GLUT_DOWN;  
}

void motion(int ax, int ay){
  x = ax;
  y = ay;
}


int main(int argc, char **argv){
    srand(time(NULL));

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
  glutInitWindowPosition(100,50);
  glutInitWindowSize(1024,600);
  glutCreateWindow("Balance Test");
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0.0, 1024, 0.0, 600, -1.0, 1.0);
  glutDisplayFunc(draw);
  timer();
  glutMouseFunc(mouse);
  glutMotionFunc(motion);
  glutMainLoop();
  return 0;
}
